package com.burton.dp.dIsAtomicInt;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.atomic.AtomicValue;
import org.apache.curator.framework.recipes.atomic.DistributedAtomicInteger;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.retry.RetryNTimes;

public class AtomDemo {

	static String path = "/count_path";
	static CuratorFramework client = CuratorFrameworkFactory.builder()
			.connectString("127.0.0.1:2181").sessionTimeoutMs(5000)
			.retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();

	public static void main(String[] args) throws Exception {
		client.start();
		DistributedAtomicInteger atom = new DistributedAtomicInteger(client,
				path, new RetryNTimes(3, 1000));
		AtomicValue<Integer> rc =atom.add(8);
//		Thread.sleep(2000);
		System.out.println(rc.postValue());
		System.out.println("result:"+rc.succeeded());
		
	}

}
